home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EBKSRC.ARJ / EB4.CPP < prev    next >
C/C++ Source or Header  |  1991-07-31  |  4KB  |  214 lines

  1. /*
  2.  
  3.     eb4.cpp
  4.     7-31-91
  5.     Electronic Book
  6.  
  7.  
  8.     Copyright 1991
  9.     John W. Small
  10.     All rights reserved
  11.  
  12.     Licensed users of FlexList may use and modify this
  13.     tool for use in their programs.
  14.  
  15.  
  16.     PSW / Power SoftWare
  17.     P.O. Box 10072
  18.     McLean, Virginia 22102 8072 USA
  19.  
  20.     Voice: (703) 759-3838
  21.     CIS: 73757,2233
  22.  
  23.  
  24.     Notes:  The Electronic Book was coded to demonstrate
  25.     the various uses of FlexList.
  26.  
  27.  
  28. */
  29.  
  30. #include <process.h>
  31. #include <ctype.h>
  32. #include <eb4.hpp>
  33.  
  34. #ifndef PICKFILE_HPP
  35. #include <pickfile.hpp>
  36. #endif
  37.  
  38.  
  39.  
  40.  
  41. Arguments::Arguments(const char *A) : FlexList(FLstrings)
  42. {
  43.     int i, j, l;
  44.  
  45.     V = (char **)0;
  46.     if (!A)
  47.         return;
  48.     for (i = j = 0; A[i] && i < MAX_HYPER_LINE; i = j) {
  49.         while (isspace(A[i]))
  50.             i++;
  51.         for (j = i; A[j] && !isspace(A[j]); j++)
  52.             /* null stmt */;
  53.         if (j > i && (l = (j-i)) < MAX_ARG_LEN)  {
  54.             strncpy(buf,&A[i],l);
  55.             buf[l] = '\0';
  56.             insQD(buf);
  57.         }
  58.     }
  59.     V = (char **) packPtrs();
  60. }
  61.  
  62.  
  63.  
  64. int HyperView::view(const char * hyperFname, const char * topic)
  65. {
  66.     PickFile pf;
  67.     TargetParser tp;
  68.     ArgumentS A;
  69.     enum HC_ACTIONS hca;
  70.  
  71.     if (hyperFname)
  72.         hstk.pushTarget(hyperFname,topic);
  73.     while (1)  {
  74.         if (!hstk.targets()) if (pf.choose
  75.             ((char *)0,FA_DIREC,".htx"))
  76.             hstk.pushTarget(pf.choice());
  77.         else
  78.             return -1;
  79.         if ((HC = hser.fetch(hstk.topTarget()))
  80.             == HyperContexT0)  {
  81.             hstk.popTarget();
  82.             continue;
  83.         }
  84.         while (HC)  {
  85.         hca = HC->view();
  86.         hstk.setTopView(HC->StartColumn(),HC->StartRow(),
  87.             HC->CursorColumn(),HC->CursorRow());
  88.         switch (hca)  {
  89.         case HyperContext::HELP:
  90.             break;
  91.         case HyperContext::LOAD:
  92.             if (pf.choose((char *)0,FA_DIREC,".htx"))
  93.                 if (hstk.pushTarget(pf.choice()))  {
  94.                     delete TOC;
  95.                     delete IDX;
  96.                     TOC = PickTOC0;
  97.                     IDX = PickIDX0;
  98.                     delete HC;
  99.                     HC = HyperContexT0;
  100.                 }
  101.             break;
  102.         case HyperContext::TABLE_OF_CONTENTS:
  103.             if (!TOC) TOC = hser.TableOfContents
  104.                 (hstk.topFname());
  105.             if (TOC) if (TOC->choose(HC->TopicNum()))
  106.             if (hstk.pushTarget(hstk.topFname(),
  107.                 TOC->choice())) {
  108.                 delete HC;
  109.                 HC = HyperContexT0;
  110.             }
  111.             break;
  112.         case HyperContext::INDEX:
  113.             if (!IDX) IDX = hser.Index(hstk.topFname());
  114.             if (IDX) if (IDX->choose())
  115.             if (hstk.pushTarget(hstk.topFname(),
  116.                 IDX->choice())) {
  117.                 delete HC;
  118.                 HC = HyperContexT0;
  119.             }
  120.             break;
  121.         case HyperContext::LAUNCH:
  122.             switch (tp.parse(HC->newTarget()))  {
  123.             case TargetParser::UNKNOWN:
  124.                 break;
  125.             case TargetParser::NEAR_TOPIC:
  126.             case TargetParser::NEAR_DEFAULT:
  127.                 if (hstk.pushTarget(hstk.topFname(),
  128.                     tp.topic())) {
  129.                     delete HC;
  130.                     HC = HyperContexT0;
  131.                 }
  132.                 break;
  133.             case TargetParser::FAR_TOPIC:
  134.             case TargetParser::FAR_DEFAULT:
  135.                 if (hstk.pushTarget(tp.params(),
  136.                     tp.topic())) {
  137.                     delete TOC;
  138.                     delete IDX;
  139.                     TOC = PickTOC0;
  140.                     IDX = PickIDX0;
  141.                     delete HC;
  142.                     HC = HyperContexT0;
  143.                 }
  144.                 break;
  145.             case TargetParser::FAR_SYSTEM:
  146.                 delete TOC;
  147.                 delete IDX;
  148.                 TOC = PickTOC0;
  149.                 IDX = PickIDX0;
  150.                 delete HC;
  151.                 HC = HyperContexT0;
  152.                 textattr(LIGHTGRAY+BLACK*16);
  153.                 clrscr();
  154.                 system(tp.params());
  155.                 cputs("Press any key ...");
  156.                 getch();
  157.                 break;
  158.             case TargetParser::FAR_SPAWN:
  159.                 if ((A = new Arguments(tp.params()))
  160.                     == ArgumentS0)
  161.                     break;
  162.                 if (!A->argc())  {
  163.                     delete A;
  164.                     break;
  165.                 }
  166.                 delete TOC;
  167.                 delete IDX;
  168.                 TOC = PickTOC0;
  169.                 IDX = PickIDX0;
  170.                 delete HC;
  171.                 HC = HyperContexT0;
  172.                 textattr(LIGHTGRAY+BLACK*16);
  173.                 clrscr();
  174.                 spawnvp(P_WAIT,A->argv0(),A->argv());
  175.                 delete A;
  176.                 break;
  177.             }
  178.             break;
  179.         case HyperContext::BACKUP:
  180.             if (hstk.targets() > 1)  {
  181.                 delete TOC;
  182.                 delete IDX;
  183.                 TOC = PickTOC0;
  184.                 IDX = PickIDX0;
  185.                 delete HC;
  186.                 HC = HyperContexT0;
  187.                 hser.discard(hstk.topFname());
  188.                 hstk.popTarget();
  189.             }
  190.             break;
  191.         case HyperContext::EXIT:
  192.             delete TOC;
  193.             delete IDX;
  194.             TOC = PickTOC0;
  195.             IDX = PickIDX0;
  196.             delete HC;
  197.             HC = HyperContexT0;
  198.             return 0;
  199.         } // switch (hca)
  200.         } // while (HC)
  201.     }  // while (1)
  202.     return -1;
  203. }
  204.  
  205.  
  206. HyperView::~HyperView()
  207. {
  208.     delete HC; delete TOC; delete IDX;
  209.     while (hstk.targets()) {
  210.         hser.discard(hstk.topFname());
  211.         hstk.popTarget();
  212.     }
  213. }
  214.